<template>
  <div v-loading="loading">
    <!--表单-->
    <el-form ref="form" :model="form" :rules="rules" label-width="120px" class="dataForm">
      <!--主表数据-->
      <el-row>
        <el-col v-if="isEmpty(dealId)" :span="12">
          <el-form-item :label="$t('项目名称')" prop="dealId">
            <MainBodySelect
              v-model="form.dealId"
              parameters="deal"
              deal-type="bf"
            />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('估值时间')" prop="valuationTime">
            <DatePicker v-model="form.valuationTime" :placeholder="$t('估值时间')" @change="changeValuationAmount($event)" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('子基金整体估值') + $t('金额单位')" prop="valuationFundAmount">
            <span slot="label">
              {{ $t('子基金整体估值') }}{{ $t('金额单位') }}
            </span>
            <Money v-model="form.valuationFundAmount" unit="w" :placeholder="$t('子基金整体估值')">
              <template #append>
                <el-tooltip>
                  <span slot="content">
                    {{ $t('勾选后自动计算:【子基金所投项目/基金估值合计】+【现金及理财】') }}
                  </span>
                  <el-checkbox v-model="isAutoValuationFund" @change="changeValuationAmountAndTotal()">
                    {{ $t('自动计算') }}
                    <i class="el-icon-question" />
                  </el-checkbox>
                </el-tooltip>
              </template>
            </Money>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('出资主体所占估值') + $t('金额单位')" prop="valuationAmount">
            <Money v-model="form.valuationAmount" unit="w" :placeholder="$t('出资主体所占估值')" @change="changeValuationAmountAndTotal()">
              <template #append>
                <el-tooltip :content="$t('出资主体列表的【主体所占估值】合计')">
                  <el-button type="info" @click="form.valuationAmount = valuationAmountAfterBtn; changeValuationAmountAndTotal()">
                    <i class="el-icon-question" />
                    {{ $t('出资主体估值合计') + ':' + moneyFormat(valuationAmountAfterBtn, 'w') }}
                  </el-button>
                </el-tooltip>
              </template>
            </Money>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('子基金所投项目/基金估值合计') + $t('金额单位')" prop="totalProjectValuation">
            <span slot="label">
              {{ $t('子基金所投项目/基金估值合计') + $t('金额单位') }}
              <el-tooltip :content="$t('所投股权项目、所投基金项目的【项目估值】/【持有最新估值】合计')">
                <i class="el-icon-question" />
              </el-tooltip>
            </span>
            <Money v-model="form.totalProjectValuation" unit="w" disabled :placeholder="$t('子基金所投项目/基金估值合计')" @change="changeValuationAmountAndTotal()" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('现金及理财') + $t('金额单位')" prop="cashAndFinancial">
            <Money v-model="form.cashAndFinancial" unit="w" :placeholder="$t('现金及理财')" @change="changeValuationAmountAndTotal()" />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item :label="$t('应对方案')" prop="responsePlan">
            <el-input
              v-model="form.responsePlan"
              type="textarea"
              :placeholder="$t('应对方案')"
              show-word-limit
              maxlength="1000"
            />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item :label="$t('备注')" prop="note">
            <el-input v-model="form.note" type="textarea" :placeholder="$t('备注')" show-word-limit maxlength="1000" />
          </el-form-item>
        </el-col>
      </el-row>
      <!-- 出资主体列表 -->
      <div style="margin-top:15px;">
        <div class="area-header">
          <span class="area-header-title">{{ $t('出资主体列表') }}</span>
        </div>
        <div>
          <el-table
            v-loading="fymxLoading"
            :data="form.investorArray"
            border
            class="nowrapTable formTable"
          >
            <el-table-column :label="$t('序号')" align="center" width="50">
              <template slot-scope="scope">
                {{ scope.$index + 1 }}
              </template>
            </el-table-column>
            <el-table-column :label="$t('主体类型')" align="center">
              <template slot-scope="scope">
                <el-form-item :prop="'investorArray.' + scope.$index + '.investorType'">
                  <dict-select
                    v-model="scope.row.investorType"
                    dictionary="deal_investment_type"
                    :placeholder="$t('主体类型')"
                    disabled
                  />
                </el-form-item>
              </template>
            </el-table-column>
            <el-table-column :label="$t('主体名称')" align="center">
              <template slot-scope="scope">
                <el-form-item :prop="'investorArray.' + scope.$index + '.investorName'">
                  <el-input
                    v-model="scope.row.investorName"
                    clearable
                    disabled
                  />
                </el-form-item>
              </template>
            </el-table-column>
            <el-table-column :label="$t('实际投资金额') + $t('金额单位')" align="center">
              <template slot-scope="scope">
                <el-form-item :prop="'investorArray.' + scope.$index + '.investmentAmount'">
                  <Money v-model="scope.row.investmentAmount" unit="w" disabled />
                </el-form-item>
              </template>
            </el-table-column>
            <el-table-column :label="$t('认缴比例(%)')" align="center">
              <template #header>
                <i style="color: #ff4949;margin-right: 4px;">*</i>
                <span>{{ $t('认缴比例(%)') }}</span>
              </template>
              <template slot-scope="scope">
                <el-form-item :prop="'investorArray.' + scope.$index + '.shareholdingRatio'" :rules="formListCheck.shareholdingRatio">
                  <Ratio
                    v-model="scope.row.shareholdingRatio"
                    clearable
                  />
                </el-form-item>
              </template>
            </el-table-column>
            <el-table-column :label="$t('主体所占估值') + $t('金额单位')" align="center">
              <template slot="header" slot-scope="{}">
                <i style="color: #ff4949;margin-right: 4px;">*</i>
                <span>{{ $t('主体所占估值') + $t('金额单位') }}</span>
                <el-tooltip :content="$t('子基金整体估值 * 认缴比例,一键计算')" placement="top">
                  <el-button type="text" class="el-icon-tickets" @click="occupancyValuationCalculate(undefined)" />
                </el-tooltip>
              </template>
              <template slot-scope="scope">
                <el-form-item :prop="'investorArray.' + scope.$index + '.occupancyValuation'" :rules="formListCheck.occupancyValuation">
                  <Money v-model="scope.row.occupancyValuation" unit="w">
                    <template slot="append">
                      <el-tooltip :content="$t('子基金整体估值 * 认缴比例')" placement="top">
                        <el-button class="el-icon-tickets" type="text" @click="occupancyValuationCalculate(scope.$index)" />
                      </el-tooltip>
                    </template>
                  </Money>
                </el-form-item>
              </template>
            </el-table-column>

          </el-table>
        </div>
      </div>

      <!-- 所投标的公司 -->
      <div style="margin-top:15px;">
        <div class="area-header">
          <span class="area-header-title">{{ $t('所投股权项目') }}
            <el-tooltip placement="bottom" effect="light">
              <div slot="content">
                {{ $t('最新持股比例为0%时，不显示在列表中') }}
              </div>
              <el-button class="tipText" type="text">

                <i class="el-icon-question" />
              </el-button>
            </el-tooltip>
          </span>
        </div>
        <div>
          <el-table
            v-loading="fymxLoading"
            :data="form.companyArray"
            border
            class="nowrapTable formTable"
          >
            <el-table-column :label="$t('序号')" align="center" width="50">
              <template slot-scope="scope">
                {{ scope.$index + 1 }}
              </template>
            </el-table-column>
            <el-table-column :label="$t('公司名称')" align="center">
              <template slot-scope="scope">
                <el-form-item :prop="'companyArray.' + scope.$index + '.companyName'">
                  <el-input
                    v-model="scope.row.companyName"
                    clearable
                    disabled
                  />
                </el-form-item>
              </template>
            </el-table-column>
            <el-table-column :label="$t('最新持股比例(%)')" align="center">
              <template slot-scope="scope">
                <el-form-item :prop="'companyArray.' + scope.$index + '.shareholdingRatio'">
                  <Ratio
                    v-model="scope.row.shareholdingRatio"
                    clearable
                    disabled
                  />
                </el-form-item>
              </template>
            </el-table-column>
            <el-table-column :label="$t('估值时间')" align="center">
              <template slot="header" slot-scope="{}">
                <i style="color: #ff4949;margin-right: 4px;">*</i>
                <span>{{ $t('估值时间') }}</span>
              </template>
              <template slot-scope="scope">
                <el-form-item :rules="formListCheck.valuationTime" :prop="'companyArray.' + scope.$index + '.valuationTime'">
                  <DatePicker v-model="scope.row.valuationTime" :placeholder="$t('估值时间')" />
                </el-form-item>
              </template>
            </el-table-column>
            <el-table-column :label="$t('项目估值') + $t('金额单位')" align="center">
              <template slot="header" slot-scope="{}">
                <i style="color: #ff4949;margin-right: 4px;">*</i>
                <span>{{ $t('项目估值') + $t('金额单位') }}</span>
              </template>
              <template slot-scope="scope">
                <el-form-item :prop="'companyArray.' + scope.$index + '.occupancyValuation'" :rules="formListCheck.occupancyValuation">
                  <Money v-model="scope.row.occupancyValuation" unit="w" @change="valuationCompute" />
                </el-form-item>
              </template>
            </el-table-column>
            <el-table-column :label="$t('公司整体估值') + $t('金额单位')" align="center">
              <template slot="header" slot-scope="{}">
                <i style="color: #ff4949;margin-right: 4px;">*</i>
                <span>{{ $t('公司整体估值') + $t('金额单位') }}</span>
                <el-tooltip :content="$t('按项目估值 / 最新持股比例方式计算,一键计算')" placement="top">
                  <el-button type="text" class="el-icon-tickets" @click="companyValuationCalculate(undefined)" />
                </el-tooltip>
              </template>
              <template slot-scope="scope">
                <el-form-item :prop="'companyArray.' + scope.$index + '.companyValuation'" :rules="formListCheck.companyValuation">
                  <Money v-model="scope.row.companyValuation" unit="w">
                    <template slot="append">
                      <el-tooltip :content="$t('按项目估值 / 最新持股比例方式计算')" placement="top">
                        <el-button class="el-icon-tickets" type="text" @click="companyValuationCalculate(scope.$index)" />
                      </el-tooltip>
                    </template>
                  </Money>
                </el-form-item>
              </template>
            </el-table-column>
          </el-table>
        </div>
      </div>

      <!-- 所投基金项目 -->
      <div style="margin-top:15px;">
        <div class="area-header">
          <span class="area-header-title">{{ $t('所投基金项目') }}
            <!--            <el-tooltip placement="bottom" effect="light">-->
            <!--              <div slot="content">-->
            <!--                {{ $t('最新持股比例为0%时，不显示在列表中') }}-->
            <!--              </div>-->
            <!--              <el-button class="tipText" type="text">-->

            <!--                <i class="el-icon-question" />-->
            <!--              </el-button>-->
            <!--            </el-tooltip>-->
          </span>
        </div>
        <div>
          <el-table
            v-loading="fymxLoading"
            :data="form.bfInvestFundArray"
            border
            class="nowrapTable formTable"
          >
            <el-table-column :label="$t('序号')" align="center" width="50">
              <template slot-scope="scope">
                {{ scope.$index + 1 }}
              </template>
            </el-table-column>
            <el-table-column :label="$t('基金名称')" align="center">
              <template slot-scope="scope">
                <el-form-item :prop="'bfInvestFundArray.' + scope.$index + '.companyName'">
                  <el-input
                    v-model="scope.row.companyName"
                    clearable
                    disabled
                  />
                </el-form-item>
              </template>
            </el-table-column>
            <el-table-column :label="$t('认缴比例(%)')" align="center">
              <template slot-scope="scope">
                <el-form-item :prop="'bfInvestFundArray.' + scope.$index + '.shareholdingRatio'">
                  <Ratio
                    v-model="scope.row.shareholdingRatio"
                    clearable
                    disabled
                  />
                </el-form-item>
              </template>
            </el-table-column>
            <el-table-column :label="$t('持有最新估值') + $t('金额单位')" align="center">
              <template slot="header" slot-scope="{}">
                <i style="color: #ff4949;margin-right: 4px;">*</i>
                <span>{{ $t('持有最新估值') + $t('金额单位') }}</span>
              </template>
              <template slot-scope="scope">
                <el-form-item :prop="'bfInvestFundArray.' + scope.$index + '.occupancyValuation'" :rules="formListCheck.occupancyValuation">
                  <Money v-model="scope.row.occupancyValuation" unit="w" @change="fundValuationCompute" />
                </el-form-item>
              </template>
            </el-table-column>
            <el-table-column :label="$t('基金整体估值') + $t('金额单位')" align="center">
              <template slot="header" slot-scope="{}">
                <!--                <i style="color: #ff4949;margin-right: 4px;">*</i>-->
                <span>{{ $t('基金整体估值') + $t('金额单位') }}</span>
                <el-tooltip :content="$t('基金整体估值 = (持有最新估值 / 认缴比例) * 100')">
                  <i class="el-icon-question" />
                </el-tooltip>
              </template>
              <template slot-scope="scope">
                <el-form-item :prop="'bfInvestFundArray.' + scope.$index + '.companyValuation'" :rules="formListCheck.companyValuation">
                  <Money v-model="scope.row.companyValuation" unit="w" />
                </el-form-item>
              </template>
            </el-table-column>
          </el-table>
        </div>
      </div>

      <!-- 附件信息 -->
      <FileTable :list.sync="form.fileList" data-type="deal_bf_valuation" :business-id="autoBusinessId(dealId, form)" :btn-show="!otherBtnHide" />
    </el-form>

    <div slot="footer" class="dialog-footer" style="text-align: right;">
      <!--保存 取消按钮-->
      <save-btn has-permi="bf:valuation" :cancel-func="cancel" />
    </div>
  </div>
</template>

<script>
import {
  saveDealBfValuation,
  getDealBfValuation,
  getByTimeDealIdToInvestorList
} from '@/api/deal/bf/valuation/dealBfValuation.js'
import { listDealInvestment } from '@/api/deal/investment/dealInvestment'
import { listBfInvestGroupNoPage } from '@/api/bf/investGroup/bfInvestGroup'
import { listBfInvestFund } from '@/api/bf/investGroup/bfInvestFund'
import { ruoyiFloat } from '@/utils/ruoyi'
import MainBodySelect from '@/components/MainBodySelect'

export default {
  components: {
    MainBodySelect
  },
  data() {
    return {
      otherBtnHide: false,
      // 表单参数
      form: {
        // 出资主体
        investorArray: [],
        // 公司列表
        companyArray: [],
        // 基金项目
        bfInvestFundArray: [],
        // 文件信息
        fileList: []
      },
      // 遮罩层
      loading: false,
      dealId: this.$route.query.id,
      // 出资主体
      incomeSubjects: [],
      // 所投标的公司
      getDealList: [],
      fymxLoading: false,
      valuationAmountAfterBtn: 0,
      isAutoValuationFund: false,
      // 表单校验
      rules: {
        valuationTime: [
          { required: true, message: this.$t('必填信息'), trigger: 'blur' }
        ], valuationAmount: [
          { required: true, message: this.$t('必填信息'), trigger: 'blur' }
        ],
        valuationFundAmount: [
          { required: true, message: this.$t('必填信息'), trigger: 'blur' }
        ],
        // responsePlan: [
        //   { required: true, message: this.$t('必填信息'), trigger: 'blur' }
        // ],
        companyValuation: [
          { required: true, message: this.$t('必填信息'), trigger: 'blur' }
        ]
      },
      // 校验信息
      formListCheck: {
        valuationTime: [{ required: true, message: this.$t('必填信息'), trigger: 'change' }],
        shareholdingRatio: [{ required: true, message: this.$t('必填信息'), trigger: ['change', 'blur'] }],
        occupancyValuation: [{ required: true, message: this.$t('必填信息'), trigger: ['change', 'blur'] }]
      }
    }
  },
  watch: {
    'form.valuationAmount'() {
      if (this.form.investorArray && this.form.investorArray.length === 1 && this.isEmpty(this.form.id)) {
        this.$set(this.form.investorArray[0], 'occupancyValuation', this.form.valuationAmount)
      }
      // } else {
      // for (let i = 0; i < this.form.investorArray.length; i++) {
      //   if (this.form.investorArray[i].shareholdingRatio && this.form.investorArray[i].shareholdingRatio !== '' && !this.form.id) {
      //     this.form.investorArray[i].occupancyValuation = val * this.form.investorArray[i].shareholdingRatio / 100
      //   }
      // }
      // this.form = JSON.parse(JSON.stringify(this.form))
      this.$forceUpdate()
    },
    'form.investorArray': {
      handler(val) {
        // 计算出资出资合计金额
        this.valuationAmountAfterBtn = 0
        val && val.forEach(item => {
          if (!isNaN(item.occupancyValuation)) {
            this.valuationAmountAfterBtn += ruoyiFloat().formatNum(item.occupancyValuation)
          }
        })
        this.$forceUpdate()
      },
      deep: true,
      immediate: true
    }
  },
  created() {

  },
  methods: {
    // 初始化数据
    init(data) {
      if (data != null && data.id !== undefined) {
        getDealBfValuation(data.id).then(response => {
          this.form = response.data
          this.form.dealId = this.dealId
          // 初始化主体和公司信息
        })
      } else {
        this.reset()
        this.dataEcho()
      }
    },
    // 表单重置
    reset() {
      this.form = {
        id: undefined,
        dealId: this.dealId,
        createBy: undefined,
        createTime: undefined,
        updateBy: undefined,
        updateTime: undefined,
        delFlag: undefined,
        valuationTime: undefined,
        valuationAmount: undefined,
        valuationFundAmount: undefined,
        responsePlan: undefined,
        note: undefined,
        totalProjectValuation: undefined,
        cashAndFinancial: undefined,
        // 出资主体
        investorArray: [],
        // 公司列表
        companyArray: [],
        // 文件信息
        fileList: []
      }

      this.resetForm('form')
    },
    // 取消按钮
    cancel() {
      if (this.$parent.$parent.dealBfValuationOpen !== undefined) {
        this.$parent.$parent.dealBfValuationOpen = false
      } else {
        this.$parent.$parent.formOpen = false
        this.$parent.$parent.reset()
      }
    },
    // 关闭form页面
    closeForm() {
      // 关闭form页面遮罩层
      this.loading = false
      // 关闭form页面
      if (this.$parent.$parent.dealBfValuationOpen !== undefined) {
        this.$parent.$parent.dealBfValuationOpen = false
      } else {
        this.$parent.$parent.formOpen = false
        // 刷新list页面
        this.$parent.$parent.getList()
      }
    },
    // 提交按钮
    submitForm: function() {
      this.$refs['form'].validate(valid => {
        if (valid) {
          this.loading = true
          saveDealBfValuation(this.form).then(response => {
            if (response.code === 200) {
              this.msgSuccess(this.$t('保存成功'))
              // 从基金估值处快速添加
              this.fundValuationQuickAdd()
              this.closeForm()
            } else {
              this.msgError(response.msg)
            }
            this.loading = false
          })
        } else {
          this.locationError(document)
        }
      })
    },
    /** 基金估值页面快速添加 **/
    fundValuationQuickAdd() {
      if (this.$parent.$parent.fundValuationQuickAddData !== undefined) {
        // 该方法调用时, 该页面为基金估值页面, 且为快速添加
        var fundId = this.$route.query.id
        var ratio = 0
        var valuationMoney = 0
        this.form.investorArray && this.form.investorArray.forEach(item => {
          if (item.investorId === fundId) {
            ratio = item.shareholdingRatio
            valuationMoney = item.occupancyValuation
          }
        })
        const data = {
          dealId: this.form.dealId,
          latestValuationTime: this.form.valuationTime,
          dealLatestValuation: this.form.valuationAmount,
          shareholdingRatio: ratio,
          fundValuation: valuationMoney,
          type: 'bf'
        }
        this.$emit('fundValuationQuickAddData', data)
      }
    },
    // 出资主体
    getlistDealInvestment() {
      listDealInvestment({ 'dealId': this.dealId }).then(response => {
        const rows = response.rows
        for (let i = 0; i < rows.length; i++) {
          const row = rows[i]
          const investor = {
            num: i + 1,
            investorId: row.investorId,
            investorName: row.investorName,
            investorType: row.investorType,
            dealId: this.dealId,
            // 最新持股比例
            shareholdingRatio: row.latestShareholdingRatio === undefined ? 0 : row.latestShareholdingRatio,
            // 投资实际金额
            investmentAmount: row.amountInvestmentFact === undefined ? 0 : row.amountInvestmentFact
          }
          console.log(row)
          if (!(this.form.investorArray instanceof Array)) {
            this.$set(this.form, 'investorArray', [])
          }
          this.form.investorArray.push(investor)
        }
      })
    },
    // 所投标公司
    companyInfo() {
      listBfInvestGroupNoPage({ 'dealId': this.dealId }).then(response => {
        this.getDealList = response.data
        const rows = response.data
        for (let i = 0; i < rows.length; i++) {
          const row = rows[i]
          if (row.latestShareholdingRatio === undefined || row.latestShareholdingRatio === 0) {
            continue
          }
          const investor = {
            num: i + 1,
            companyId: row.company.id,
            companyName: row.company.companyName,
            dealId: this.dealId,
            // 最新持股比例
            shareholdingRatio: row.latestShareholdingRatio === undefined ? 0 : row.latestShareholdingRatio,
            companyValuation: row.company.companyValuation,
            valuationTime: row.company.valuationTime,
            occupancyValuation: row.company.occupancyValuation
          }
          if (!(this.form.companyArray instanceof Array)) {
            this.$set(this.form, 'companyArray', [])
          }
          this.form.companyArray.push(investor)
          this.valuationCompute()
        }
      })
    },
    // 所投基金项目
    bfInvestFundInfo() {
      listBfInvestFund({ 'dealId': this.dealId, notStatus: 'QBTC' }).then(response => {
        const rows = response.rows
        console.log(rows)
        for (let i = 0; i < rows.length; i++) {
          const row = rows[i]
          console.log(row)
          // if (row.latestShareholdingRatio === undefined || row.latestShareholdingRatio === 0) {
          //   continue
          // }
          const investFund = {
            num: i + 1,
            companyId: row.id,
            companyName: row.fundName,
            bfId: this.$route.query.bfId,
            // 认缴比例
            shareholdingRatio: row.subscriptionRatio,
            occupancyValuation: row.valuation,
            companyValuation: row.valuation / row.subscriptionRatio * 100
          }
          if (!(this.form.bfInvestFundArray instanceof Array)) {
            this.$set(this.form, 'bfInvestFundArray', [])
          }
          this.form.bfInvestFundArray.push(investFund)
        }
        this.valuationCompute()
      })
    },
    // 数据回显
    dataEcho(id) {
      // 没有id 单纯回显
      if (id === null || id === undefined) {
        // 出资主体
        this.getlistDealInvestment()
        // 所投标公司
        this.companyInfo()
        // 所投基金项目
        this.bfInvestFundInfo()
      }
    },
    changeValuationAmount(time) {
      console.log(time)
      if (time) {
        var _this = this
        this.$confirm(this.$t('是否同步修改所投股权项目的估值时间?'), this.$t('提示'), {
          confirmButtonText: this.$t('确定'),
          cancelButtonText: this.$t('取消'),
          type: 'warning'
        }).then(() => {
          _this.form.companyArray && _this.form.companyArray.forEach(item => {
            item.valuationTime = time
          })
          // 根据估值时间获取出资主体列表信息
          getByTimeDealIdToInvestorList(this.dealId, time).then(response => {
            console.table(response.data)
            this.form.investorArray = []
            const rows = response.data
            for (let i = 0; i < rows.length; i++) {
              const row = rows[i]
              const investor = {
                num: i + 1,
                investorId: row.investorId,
                investorName: row.investorName,
                investorType: row.investorType,
                dealId: this.dealId,
                // 最新持股比例
                shareholdingRatio: row.latestShareholdingRatio === undefined ? 0 : row.latestShareholdingRatio,
                // 投资实际金额
                investmentAmount: row.amountInvestmentFact === undefined ? 0 : row.amountInvestmentFact
              }
              console.log(row)
              if (!(this.form.investorArray instanceof Array)) {
                this.$set(this.form, 'investorArray', [])
              }
              this.form.investorArray.push(investor)
            }
            this.occupancyValuationCalculate(undefined)
          })
        }).catch(() => {
        })
      }
    },
    fundValuationCompute() {
      this.valuationCompute()
    },
    valuationCompute() {
      var sumMoney = 0.0
      if (this.form.companyArray) {
        var companySumMoney = 0.0
        this.form.companyArray.forEach(item => {
          var money = parseFloat(item.occupancyValuation)
          if (money === undefined || isNaN(money)) {
            money = 0.0
          }
          companySumMoney += money
        })
        sumMoney += companySumMoney
      }
      if (this.form.bfInvestFundArray) {
        var fundSumMoney = 0.0
        this.form.bfInvestFundArray.forEach(item => {
          var money = parseFloat(item.occupancyValuation)
          if (money === undefined || isNaN(money)) {
            money = 0.0
          }
          fundSumMoney += money
          item.companyValuation = item.occupancyValuation / item.shareholdingRatio * 100
        })
        sumMoney += fundSumMoney
      }
      if (sumMoney === 0.0 || sumMoney === 0) {
        this.form.totalProjectValuation = undefined
      } else {
        this.form.totalProjectValuation = sumMoney
      }
    },
    /**
     * 单独计算方式:计算公司整体估值
     */
    companyValuationCalculate(index) {
      if (index !== undefined) {
        if (this.isEmpty(this.form.companyArray[index].shareholdingRatio) || this.form.companyArray[index].shareholdingRatio === 0) {
          this.form.companyArray[index].companyValuation = 0
        } else {
          this.form.companyArray[index].companyValuation = ruoyiFloat().formatNum(this.form.companyArray[index].occupancyValuation / (this.form.companyArray[index].shareholdingRatio / 100))
        }
      } else {
        this.form.companyArray && this.form.companyArray.forEach(item => {
          if (this.isEmpty(item.shareholdingRatio) || item.shareholdingRatio === 0) {
            item.companyValuation = 0
          } else {
            item.companyValuation = ruoyiFloat().formatNum(item.occupancyValuation / (item.shareholdingRatio / 100))
          }
        })
      }
    },
    /** 单独计算 出资主体列表 **/
    occupancyValuationCalculate(index) {
      console.log('计算')
      this.changeValuationAmountAndTotal()
      if (index !== undefined) {
        if (this.isEmpty(this.form.investorArray[index].shareholdingRatio) || this.form.investorArray[index].shareholdingRatio === 0) {
          this.form.investorArray[index].occupancyValuation = 0
        } else {
          this.$set(this.form.investorArray[index], 'occupancyValuation', ruoyiFloat().formatNum(this.form.valuationFundAmount * (this.form.investorArray[index].shareholdingRatio / 100)))
        }
      } else {
        this.form.investorArray && this.form.investorArray.forEach((item, index) => {
          if (this.isEmpty(item.shareholdingRatio) || item.shareholdingRatio === 0) {
            item.occupancyValuation = 0
          } else {
            this.$set(this.form.investorArray[index], 'occupancyValuation', ruoyiFloat().formatNum(this.form.valuationFundAmount * (item.shareholdingRatio / 100)))
          }
        })
      }
      this.$forceUpdate()
    },
    changeValuationAmountAndTotal() {
      if (this.isAutoValuationFund) {
        var totalProjectValuation = 0
        var cashAndFinancial = 0
        if (!this.isEmpty(this.form.totalProjectValuation)) {
          totalProjectValuation = this.form.totalProjectValuation
        }
        if (!this.isEmpty(this.form.cashAndFinancial)) {
          cashAndFinancial = this.form.cashAndFinancial
        }
        this.form.valuationFundAmount = cashAndFinancial + totalProjectValuation
      }
    }
  }

}
</script>
